package com.polaris.live.widget

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import com.bumptech.glide.Glide
import com.polaris.live.databinding.WidgetCommunityMedalBinding
import com.polaris.live.utils.image.ImageUtils

/**
 * CommunityMedalView
 *
 * @author Created by 半仙 on 2024/9/5/005 11:32
 */
class CommunityMedalView(context: Context, attr: AttributeSet?) : LinearLayout(context, attr) {

    private val mBinding = WidgetCommunityMedalBinding.inflate(LayoutInflater.from(context), this, true)

    private val llList = mutableListOf<LinearLayout>()
    private val ivList = mutableListOf<ImageView>()

    init {
        llList.add(mBinding.llMedal1)
        llList.add(mBinding.llMedal2)
        llList.add(mBinding.llMedal3)
        llList.add(mBinding.llMedal4)

        ivList.add(mBinding.ivMedal1)
        ivList.add(mBinding.ivMedal2)
        ivList.add(mBinding.ivMedal3)
        ivList.add(mBinding.ivMedal4)
    }

    fun setMedal(medals: List<String>?) {
        llList.forEachIndexed { index, linearLayout ->
            val item = medals?.getOrNull(index)
            if (item != null) {
                linearLayout.visibility = View.VISIBLE
                Glide.with(context).load(ImageUtils.imgPath(item)).into(ivList[index])
            } else {
                linearLayout.visibility = View.GONE
            }
        }
    }
}